from eap_socket.hd_logger import EapLogger
import time

clientLogger = EapLogger()

BUFFER_SIZE = 16384  # 设置读取的一次BUFFER_SIZE大小.16K

def eap_print(msg):
    """
    打印消息,并且写入到debug文件中去,这个函数的目的就是有时候又要print消息
    有时候又要写入到debug目录文件中去,现在有了这个函数就是要将消息即可以打印,
    又可以写入到debug文件中.
    :param msg:
    :return:
    """
    print(msg)
    clientLogger.debug(msg)


def get_now_time_str():
    """
    获取当前时间的字符串格式类似 2024-06-20 17:41:21
    :return:
    """
    return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())


def split_recv_data(recvData):
    """
    将消息拆分成好几条消息
    :param recvData:
    :return:
    """
    start = bytes(chr(2), encoding="ascii")
    end = bytes(chr(3), encoding="ascii")

    startCount = recvData.count(start)
    endCount = recvData.count(end)

    msgCount = min(startCount, endCount)
    recvDataList = []

    for i in range(msgCount):
        indexStart = recvData.index(start)
        indexEnd = recvData.index(end)
        oneMsg = recvData[indexStart:indexEnd + 1]
        recvData = recvData[indexEnd + 1:]
        recvDataList.append(oneMsg)
    return recvDataList